/*
 * SalesAuditTrailAction.java
 *
 * Created on January 20, 2003, 9:23 PM
 */


package com.scalar.chiptrack.sales.actions;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.scalar.chiptrack.ChipTrackAction;
import com.scalar.chiptrack.commons.SessionKeys;
import com.scalar.chiptrack.sales.dao.SalesDAO;
import com.scalar.chiptrack.users.User;


/**
 *
 * @author  KUMAR
 */



/**
 * Implementation of <strong>Action</strong> that gives customers list,
 * search with customer name, create sales order
 *
 * @author Kesava Kumar Achanala
 * @version $Revision: 1.1.1.1 $ $Date: 2006/12/11 23:43:17 $
 */

public final class SalesAuditTrailAction extends ChipTrackAction {

    private static final String ACTION_NAME = "/salesAuditTrail.do" ;  // Added by Basha (08/08/2003)

    // ----------------------------------------------------- Instance Variables
        
   

    // --------------------------------------------------------- Public Methods


    /**
     * Process the specified HTTP request, and create the corresponding HTTP
     * response (or forward to another web component that will create it).
     * Return an <code>ActionForward</code> instance describing where and how
     * control should be forwarded, or <code>null</code> if the response has
     * already been completed.
     *
     * @param mapping The ActionMapping used to select this instance
     * @param form The optional ActionForm bean for this request (if any)
     * @param request The HTTP request we are processing
     * @param response The HTTP response we are creating
     *
     * @exception Exception if business logic throws an exception
     */
    public ActionForward execute(ActionMapping mapping,
				 ActionForm form,
				 HttpServletRequest request,
				 HttpServletResponse response)
    	throws Exception
    {
            HashMap errors = new HashMap();
            HttpSession session = request.getSession();
            User user = (User)session.getAttribute (SessionKeys.USER_KEY);

            // Added by Basha (08/08/2003)
            if(user == null)
            {
	            session.setAttribute (SessionKeys.SOURCE_PAGE_KEY, ACTION_NAME + "?" + request.getQueryString());
                return (mapping.findForward ("login"));
            }
            // Added by Basha (08/08/2003)

                String salesOrderId = (String)request.getParameter("salesOrderId");
        try
        {

                request.setAttribute("auditTrail", SalesDAO.loadSalesAuditTrail(salesOrderId));
        }
        catch( Exception ex )
        {
            errors.put( ERROR_INTERNAL_SERVER_ERROR, ERROR_IN_LOADING_SALES_AUDIT_TRAIL );
            errors.put( ERROR_MESSAGE_CONTACT_SYS_ADMN, null );
            session.setAttribute( SessionKeys.ERROR_REPORT_SUBJECT, " Error: Could Not load Sales Audit Trial.");
            session.setAttribute( SessionKeys.ERROR_REPORT, ex );
        }
            if(!errors.isEmpty())
                request.setAttribute(SessionKeys.ERROR_MESSAGES,errors);


            return (mapping.findForward("success"));


    }

}
